/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Giaodien;

import javax.swing.JOptionPane;
import javax.swing.SpinnerDateModel;
import javax.swing.SpinnerModel;
import net.proteanit.sql.DbUtils;
import oracle.jdbc.OracleResultSet;
import Lop.lKHU_TDC;
import Lop.lDIACHI;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JSpinner;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author lhqbao
 */
public class gKHU_TDC extends javax.swing.JInternalFrame {

    /**
     * Creates new form gKHU_TDC1
     */
    private int flag=0;
    public gKHU_TDC() {
        initComponents();
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        txtMakhu = new javax.swing.JTextField();
        txtTenkhu = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        lbtest = new javax.swing.JLabel();
        pNgaybd = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        txtSo = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtDuong = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        txtPhuong = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        txtQuanhuyen = new javax.swing.JTextField();
        dNgaysudung = new com.toedter.calendar.JDateChooser();
        jPanel2 = new javax.swing.JPanel();
        btThem = new javax.swing.JButton();
        btSua = new javax.swing.JButton();
        btXoa = new javax.swing.JButton();
        btThoat = new javax.swing.JButton();
        btLuu = new javax.swing.JButton();
        btBoqua = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbKHU_TDC = new javax.swing.JTable();
        label1 = new java.awt.Label();

        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameOpened(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        jLabel1.setText("Mã khu");

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        jLabel2.setText("Ngày sử dụng");

        txtMakhu.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        txtMakhu.setEnabled(false);
        txtMakhu.setName("txtMakhu"); // NOI18N

        txtTenkhu.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        txtTenkhu.setName("txtTenkhu"); // NOI18N

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        jLabel3.setText("Tên khu");

        javax.swing.GroupLayout pNgaybdLayout = new javax.swing.GroupLayout(pNgaybd);
        pNgaybd.setLayout(pNgaybdLayout);
        pNgaybdLayout.setHorizontalGroup(
            pNgaybdLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        pNgaybdLayout.setVerticalGroup(
            pNgaybdLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 35, Short.MAX_VALUE)
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel4.setText("Số");

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        jLabel5.setText("Thông tin địa chỉ");

        jLabel6.setText("Đường");

        jLabel7.setText("Phường");

        jLabel8.setText("Quận/Huyện");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE))
                            .addComponent(jLabel8))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtSo, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtPhuong, javax.swing.GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE)
                            .addComponent(txtDuong)
                            .addComponent(txtQuanhuyen))))
                .addContainerGap(125, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(7, 7, 7)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtSo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(txtDuong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(txtPhuong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(txtQuanhuyen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(24, Short.MAX_VALUE))
        );

        dNgaysudung.setDateFormatString("dd-MM-yyyy");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE)
                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtTenkhu, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtMakhu, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(dNgaysudung, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(28, 28, 28)
                .addComponent(pNgaybd, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lbtest, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtMakhu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtTenkhu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(dNgaysudung, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(5, 5, 5)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(lbtest, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(67, 67, 67))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(106, 106, 106)
                                .addComponent(pNgaybd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(26, Short.MAX_VALUE))))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        btThem.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        btThem.setText("Them ");
        btThem.setName("btThem"); // NOI18N
        btThem.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btThemMouseClicked(evt);
            }
        });

        btSua.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        btSua.setText("Sua");
        btSua.setName("btSua"); // NOI18N
        btSua.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btSuaMouseClicked(evt);
            }
        });

        btXoa.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        btXoa.setText("Xoa");
        btXoa.setName("btXoa"); // NOI18N
        btXoa.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btXoaMouseClicked(evt);
            }
        });

        btThoat.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        btThoat.setText("Thoat");
        btThoat.setName("btThoat"); // NOI18N
        btThoat.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btThoatMouseClicked(evt);
            }
        });
        btThoat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btThoatActionPerformed(evt);
            }
        });

        btLuu.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        btLuu.setText("Luu");
        btLuu.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btLuuMouseClicked(evt);
            }
        });
        btLuu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btLuuActionPerformed(evt);
            }
        });

        btBoqua.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        btBoqua.setText("Bo qua");
        btBoqua.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btBoquaMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btThem, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btLuu, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(8, 8, 8)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(btBoqua, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(2, 2, 2))
                    .addComponent(btSua, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btXoa, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btThoat, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(76, 76, 76))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btThem, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btSua, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btXoa, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btThoat, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(btBoqua, javax.swing.GroupLayout.DEFAULT_SIZE, 28, Short.MAX_VALUE)
                    .addComponent(btLuu, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        tbKHU_TDC.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Mã khu", "Tên khu", "Ngày đưa vào sư dụng"
            }
        ));
        tbKHU_TDC.setName("tbKHU_TDC"); // NOI18N
        tbKHU_TDC.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tbKHU_TDCMouseClicked(evt);
            }
        });
        tbKHU_TDC.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                tbKHU_TDCPropertyChange(evt);
            }
        });
        jScrollPane1.setViewportView(tbKHU_TDC);

        label1.setFont(new java.awt.Font("Dialog", 1, 24)); // NOI18N
        label1.setForeground(new java.awt.Color(0, 0, 255));
        label1.setText("THÔNG TIN KHU TÁI ĐỊNH CƯ");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 443, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(308, Short.MAX_VALUE)
                .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(216, 216, 216))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane1))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    private void btThemMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btThemMouseClicked
        // TODO add your handling code here:
        
        flag=1;
        txtMakhu.setText(null);
        txtTenkhu.setText(null);
        dNgaysudung.setDate(null);
        txtSo.setText(null);
        txtDuong.setText(null);
        txtPhuong.setText(null);
        txtQuanhuyen.setText(null);
        
        txtMakhu.setEnabled(true);
        txtTenkhu.setEnabled(true);
        dNgaysudung.setEnabled(true);
        txtSo.setEnabled(true);
        txtDuong.setEnabled(true);
        txtPhuong.setEnabled(true);
        txtQuanhuyen.setEnabled(true);
        
        btThem.setVisible(false);
        btSua.setVisible(false);
        btXoa.setVisible(false);
        btThoat.setVisible(false);
        btLuu.setVisible(true);
        btBoqua.setVisible(true);
        txtMakhu.setEnabled(true);
        
           
        
        
    }//GEN-LAST:event_btThemMouseClicked
    public void hienthiKHU_TDC() 
    {
        flag=0;
        
        txtMakhu.setEnabled(false);
        txtTenkhu.setEnabled(false);
        dNgaysudung.setEnabled(false);
        txtSo.setEnabled(false);
        txtDuong.setEnabled(false);
        txtPhuong.setEnabled(false);
        txtQuanhuyen.setEnabled(false);
        
        btThem.setVisible(true);
        btSua.setVisible(true);
        btXoa.setVisible(true);
        btThoat.setVisible(true);
             
        btLuu.setVisible(false);
        btBoqua.setVisible(false);
        
        OracleResultSet rs = new lKHU_TDC().hienthiKHU_TDC(fMain.cnn);
        tbKHU_TDC.setModel(DbUtils.resultSetToTableModel(rs));
               
    }
    // Kiem tra nhap lieu
    public boolean kiemtra()
    {
        if(txtMakhu.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Vui long nhap ma khu");
            return false; 
        }
        if(txtTenkhu.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Vui long nhap ten khu");
            return false;
        }
        if(dNgaysudung.getDate().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Vui long chon ngay dua vao su dung");
            return false;
        }
        if(txtSo.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Vui long nhap so");
            return false;
        }
        if(txtDuong.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Vui long nhap vao duong");
            return false;
        }
        if(txtPhuong.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Vui long nhap vao phuong");
            return false;
        }
        if(txtQuanhuyen.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Vui long nhap vao quan huyen");
            return false;
        }
        return true;
    }
    private void btSuaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btSuaMouseClicked
        // TODO add your handling code here:
        flag=2;
        txtMakhu.setEnabled(false);
        if(txtMakhu.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Vui long chon khu de sua");
            return;
        }
       
        txtTenkhu.requestFocusInWindow();
        txtTenkhu.setEnabled(true);
        dNgaysudung.setEnabled(true);
        txtSo.setEnabled(true);
        txtDuong.setEnabled(true);
        txtPhuong.setEnabled(true);
        txtQuanhuyen.setEnabled(true);
        
        btThem.setVisible(false);
        btThoat.setVisible(false);
        btSua.setVisible(false);
        btXoa.setVisible(false);
        
        btLuu.setVisible(true);
        btBoqua.setVisible(true);
    }//GEN-LAST:event_btSuaMouseClicked

    private void btXoaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btXoaMouseClicked
        // TODO add your handling code here:
        
        if(txtMakhu.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Vui long chon khu de xoa");
            return;
        }
        
        int reply = JOptionPane.showConfirmDialog(null, "Ban co chac xoa khong ?", "Xac nhan xoa", JOptionPane.YES_NO_OPTION);
        if (reply == JOptionPane.YES_OPTION)
        {
                java.util.Date utilDate = (java.util.Date) dNgaysudung.getDate();
                java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
                
                lKHU_TDC khu_tdc = new lKHU_TDC();
                khu_tdc.setMakhu(txtMakhu.getText());
                khu_tdc.xoaKHU_TDC(fMain.cnn);
                JOptionPane.showMessageDialog(null, "Xoa thanh cong!");
                flag=0;
        }
       hienthiKHU_TDC();
    }//GEN-LAST:event_btXoaMouseClicked

    private void btThoatMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btThoatMouseClicked
        // TODO add your handling code here:
        dispose();
    }//GEN-LAST:event_btThoatMouseClicked

    private void btThoatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btThoatActionPerformed
        // TODO add your handling code here:
        /*
        dispose();
        new Sub_main_QLTDC().setVisible(true);
        */
    }//GEN-LAST:event_btThoatActionPerformed

    private void btLuuMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btLuuMouseClicked
        // TODO add your handling code here:
        
        if(!kiemtra()) return;
        try{
            if(flag==1)
            {   
                java.util.Date utilDate = (java.util.Date) dNgaysudung.getDate();
                java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
        
                lDIACHI dchi = new lDIACHI(txtSo.getText(), txtDuong.getText(), txtPhuong.getText(), txtQuanhuyen.getText());
                lKHU_TDC khu_tdc = new lKHU_TDC(txtMakhu.getText(), txtTenkhu.getText(), sqlDate, dchi);
                khu_tdc.themKHU_TDC(fMain.cnn);
                JOptionPane.showMessageDialog(null, "Them thanh cong!");
                flag=0;
            }
            if(flag==2)
            {
                java.util.Date utilDate = (java.util.Date) dNgaysudung.getDate();
                java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());

                lDIACHI dchi = new lDIACHI(txtSo.getText(), txtDuong.getText(), txtPhuong.getText(), txtQuanhuyen.getText());
                lKHU_TDC khu_tdc = new lKHU_TDC(txtMakhu.getText(), txtTenkhu.getText(), sqlDate, dchi);
                khu_tdc.suaKHU_TDC(fMain.cnn);
                JOptionPane.showMessageDialog(null, "Cap nhat thanh cong!");
                flag=0;
            }
        }catch(Exception e)
        {
            JOptionPane.showMessageDialog(null, "Cap nhat khong thanh cong");
        }
        hienthiKHU_TDC();
       
    }//GEN-LAST:event_btLuuMouseClicked

    private void btLuuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btLuuActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btLuuActionPerformed

    private void btBoquaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btBoquaMouseClicked
        // TODO add your handling code here:
        
        hienthiKHU_TDC();
        try{
        DefaultTableModel model = (DefaultTableModel) tbKHU_TDC.getModel();
        txtMakhu.setText((String) model.getValueAt(tbKHU_TDC.getSelectedRow(), 0));
        txtTenkhu.setText((String) model.getValueAt(tbKHU_TDC.getSelectedRow(), 1));
        
        String dateValue = model.getValueAt(tbKHU_TDC.getSelectedRow(), 2).toString(); // What ever column
        java.util.Date date = new SimpleDateFormat("dd-MM-yyyy").parse(dateValue);
        dNgaysudung.setDate(date);
        
        txtSo.setText((String) model.getValueAt(tbKHU_TDC.getSelectedRow(), 3));
        txtDuong.setText((String) model.getValueAt(tbKHU_TDC.getSelectedRow(), 4));
        txtPhuong.setText((String) model.getValueAt(tbKHU_TDC.getSelectedRow(), 5));
        txtQuanhuyen.setText((String) model.getValueAt(tbKHU_TDC.getSelectedRow(), 6));
        }catch(Exception e){}
        
    }//GEN-LAST:event_btBoquaMouseClicked

    private void tbKHU_TDCMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbKHU_TDCMouseClicked
        // TODO add your handling code here:
        try{
        DefaultTableModel model = (DefaultTableModel) tbKHU_TDC.getModel();
        txtMakhu.setText((String) model.getValueAt(tbKHU_TDC.getSelectedRow(), 0));
        txtTenkhu.setText((String) model.getValueAt(tbKHU_TDC.getSelectedRow(), 1));
        
        String dateValue = model.getValueAt(tbKHU_TDC.getSelectedRow(), 2).toString(); // What ever column
        java.util.Date date = new SimpleDateFormat("dd-MM-yyyy").parse(dateValue);
        dNgaysudung.setDate(date);
        
        txtSo.setText((String) model.getValueAt(tbKHU_TDC.getSelectedRow(), 3));
        txtDuong.setText((String) model.getValueAt(tbKHU_TDC.getSelectedRow(), 4));
        txtPhuong.setText((String) model.getValueAt(tbKHU_TDC.getSelectedRow(), 5));
        txtQuanhuyen.setText((String) model.getValueAt(tbKHU_TDC.getSelectedRow(), 6));
        }catch(Exception e)
        {
            JOptionPane.showMessageDialog(null, e);
        }
    }//GEN-LAST:event_tbKHU_TDCMouseClicked

    private void tbKHU_TDCPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_tbKHU_TDCPropertyChange
        // TODO add your handling code here:
      
    }//GEN-LAST:event_tbKHU_TDCPropertyChange

    private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameOpened
        // TODO add your handling code here:
        hienthiKHU_TDC();
    }//GEN-LAST:event_formInternalFrameOpened


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btBoqua;
    private javax.swing.JButton btLuu;
    private javax.swing.JButton btSua;
    private javax.swing.JButton btThem;
    private javax.swing.JButton btThoat;
    private javax.swing.JButton btXoa;
    private com.toedter.calendar.JDateChooser dNgaysudung;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private java.awt.Label label1;
    private javax.swing.JLabel lbtest;
    private javax.swing.JPanel pNgaybd;
    private javax.swing.JTable tbKHU_TDC;
    private javax.swing.JTextField txtDuong;
    private javax.swing.JTextField txtMakhu;
    private javax.swing.JTextField txtPhuong;
    private javax.swing.JTextField txtQuanhuyen;
    private javax.swing.JTextField txtSo;
    private javax.swing.JTextField txtTenkhu;
    // End of variables declaration//GEN-END:variables
}
